package com.zdy564.study.myapplication.net;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zdy564.study.myapplication.test.GsonTest;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class NetManager {
    public void test()
    {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://154.90.63.210")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        IUserNetInterface apiRetrofit = retrofit.create(IUserNetInterface.class);
        RequestTestModel.UserLogin para = new RequestTestModel.UserLogin();
        para.setUserName("zdy564");
        para.setPassword("Dayong564!@#");
        String paraStr = new Gson().toJson(para);
        Log.i("zdy564",paraStr);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), paraStr);
        Log.i("zdy564",requestBody.toString());
        Call<GsonTest.NetResult<RequestTestModel.UserLoginResult>> call = apiRetrofit.userLogin(requestBody);
        call.enqueue(new Callback<GsonTest.NetResult<RequestTestModel.UserLoginResult>>() {
            @Override
            public void onResponse(Call<GsonTest.NetResult<RequestTestModel.UserLoginResult>> call, Response<GsonTest.NetResult<RequestTestModel.UserLoginResult>> response) {
                Log.i("zdy564","succed:"+new Gson().toJson(response.body()));
            }

            @Override
            public void onFailure(Call<GsonTest.NetResult<RequestTestModel.UserLoginResult>> call, Throwable t) {
                Log.i("zdy564","failed:"+t.toString());
            }
        });
    }
}
